{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.10.1+17.ge9b9b47.dirty\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import folium\n",
    "\n",
    "print(folium.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "\n",
    "def sample_data(shape=(73, 145)):\n",
    "    nlats, nlons = shape\n",
    "    lats = np.linspace(-np.pi / 2, np.pi / 2, nlats)\n",
    "    lons = np.linspace(0, 2 * np.pi, nlons)\n",
    "    lons, lats = np.meshgrid(lons, lats)\n",
    "    wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)\n",
    "    mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)\n",
    "\n",
    "    lats = np.rad2deg(lats)\n",
    "    lons = np.rad2deg(lons)\n",
    "    data = wave + mean\n",
    "\n",
    "    return lons, lats, data\n",
    "\n",
    "\n",
    "lon, lat, data = sample_data(shape=(73, 145))\n",
    "lon -= 180"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "import matplotlib\n",
    "\n",
    "cm = matplotlib.cm.get_cmap('cubehelix')\n",
    "\n",
    "normed_data = (data - data.min()) / (data.max() - data.min())\n",
    "colored_data = cm(normed_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgIC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QwZCB7CiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb246IHJlbGF0aXZlOwogICAgICAgICAgICAgICAgICAgIHdpZHRoOiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgbGVmdDogMC4wJTsKICAgICAgICAgICAgICAgICAgICB0b3A6IDAuMCU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCiAgICAKICAgICAgICAgICAgICAgIDxzdHlsZT4KICAgICAgICAgICAgICAgICAgICAubGVhZmxldC1pbWFnZS1sYXllciB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIG9sZCBhbmRyb2lkL3NhZmFyaSovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogLXdlYmtpdC1vcHRpbWl6ZS1jb250cmFzdDsKICAgICAgICAgICAgICAgICAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBjcmlzcC1lZGdlczsgLyogc2FmYXJpICovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogcGl4ZWxhdGVkOyAvKiBjaHJvbWUgKi8KICAgICAgICAgICAgICAgICAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiAtbW96LWNyaXNwLWVkZ2VzOyAvKiBmaXJlZm94ICovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogLW8tY3Jpc3AtZWRnZXM7IC8qIG9wZXJhICovCiAgICAgICAgICAgICAgICAgICAgICAgIC1tcy1pbnRlcnBvbGF0aW9uLW1vZGU6IG5lYXJlc3QtbmVpZ2hib3I7IC8qIGllICovCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgPC9zdHlsZT4KICAgICAgICAgICAgCjwvaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICAgICAgICAgIDxkaXYgY2xhc3M9ImZvbGl1bS1tY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zZjE0ZWQwZCk7CiAgICAgICAgCjwvc2NyaXB0Pg== onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x217e63969c8>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
    "\n",
    "folium.raster_layers.ImageOverlay(\n",
    "    image=colored_data,\n",
    "    bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
    "    opacity=0.25\n",
    ").add_to(m)\n",
    "\n",
    "m.save(os.path.join('results', 'GeodedeticImageOverlay_0.html'))\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Good"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD4KICAgIAogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vbGVhZmxldEAxLjYuMC9kaXN0L2xlYWZsZXQuanMiPjwvc2NyaXB0PgogICAgPHNjcmlwdCBzcmM9Imh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c29tZS1tYXJrZXJzLmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL3Jhd2Nkbi5naXRoYWNrLmNvbS9weXRob24tdmlzdWFsaXphdGlvbi9mb2xpdW0vbWFzdGVyL2ZvbGl1bS90ZW1wbGF0ZXMvbGVhZmxldC5hd2Vzb21lLnJvdGF0ZS5jc3MiLz4KICAgIDxzdHlsZT5odG1sLCBib2R5IHt3aWR0aDogMTAwJTtoZWlnaHQ6IDEwMCU7bWFyZ2luOiAwO3BhZGRpbmc6IDA7fTwvc3R5bGU+CiAgICA8c3R5bGU+I21hcCB7cG9zaXRpb246YWJzb2x1dGU7dG9wOjA7Ym90dG9tOjA7cmlnaHQ6MDtsZWZ0OjA7fTwvc3R5bGU+CiAgICAKICAgICAgICAgICAgPG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRoPWRldmljZS13aWR0aCwKICAgICAgICAgICAgICAgIGluaXRpYWwtc2NhbGU9MS4wLCBtYXhpbXVtLXNjYWxlPTEuMCwgdXNlci1zY2FsYWJsZT1ubyIgLz4KICAgICAgICAgICAgPHN0eWxlPgogICAgICAgICAgICAgICAgI21hcF8yNWFhNzM5MjgzNWY0OGE2ODBlZGJmOTA0MWViZTBiMyB7CiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb246IHJlbGF0aXZlOwogICAgICAgICAgICAgICAgICAgIHdpZHRoOiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgbGVmdDogMC4wJTsKICAgICAgICAgICAgICAgICAgICB0b3A6IDAuMCU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCiAgICAKICAgICAgICAgICAgICAgIDxzdHlsZT4KICAgICAgICAgICAgICAgICAgICAubGVhZmxldC1pbWFnZS1sYXllciB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIG9sZCBhbmRyb2lkL3NhZmFyaSovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogLXdlYmtpdC1vcHRpbWl6ZS1jb250cmFzdDsKICAgICAgICAgICAgICAgICAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBjcmlzcC1lZGdlczsgLyogc2FmYXJpICovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogcGl4ZWxhdGVkOyAvKiBjaHJvbWUgKi8KICAgICAgICAgICAgICAgICAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiAtbW96LWNyaXNwLWVkZ2VzOyAvKiBmaXJlZm94ICovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogLW8tY3Jpc3AtZWRnZXM7IC8qIG9wZXJhICovCiAgICAgICAgICAgICAgICAgICAgICAgIC1tcy1pbnRlcnBvbGF0aW9uLW1vZGU6IG5lYXJlc3QtbmVpZ2hib3I7IC8qIGllICovCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgPC9zdHlsZT4KICAgICAgICAgICAgCjwvaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICAgICAgICAgIDxkaXYgY2xhc3M9ImZvbGl1bS1tYXAiIGlkPSJtYXBfMjVhYTczOTI4MzVmNDhhNjgwZWRiZjkwNDFlYmUwYjMiID48L2Rpdj4KICAgICAgICAKPC9ib2R5Pgo8c2NyaXB0PiAgICAKICAgIAogICAgICAgICAgICB2YXIgbWFwXzI1YWE3MzkyODM1ZjQ4YTY4MGVkYmY5MDQxZWJlMGIzID0gTC5tYXAoCiAgICAgICAgICAgICAgICAibWFwXzI1YWE3MzkyODM1ZjQ4YTY4MGVkYmY5MDQxZWJlMGIzIiwKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBjZW50ZXI6IFswLjAsIC04LjU5MjI5NzYwNzY4MDAwMmUtMTddLAogICAgICAgICAgICAgIC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9OMDhGNXVrRUFBQUFBU1VWT1JLNUNZSUk9IiwKICAgICAgICAgICAgICAgIFtbLTkwLjAsIC0xODAuMF0sIFs5MC4wLCAxODAuMF1dLAogICAgICAgICAgICAgICAgeyJvcGFjaXR5IjogMC4yNX0KICAgICAgICAgICAgKS5hZGRUbyhtYXBfMjVhYTczOTI4MzVmNDhhNjgwZWRiZjkwNDFlYmUwYjMpOwogICAgICAgIAo8L3NjcmlwdD4= onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x217e63c9a88>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
    "\n",
    "folium.raster_layers.ImageOverlay(\n",
    "    image=colored_data,\n",
    "    bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
    "    mercator_project=True,\n",
    "    opacity=0.25\n",
    ").add_to(m)\n",
    "\n",
    "m.save(os.path.join('results', 'GeodedeticImageOverlay_1.html'))\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Same as above but with cartopy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VD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AgICAgICAgICAgbGVmdDogMC4wJTsKICAgICAgICAgICAgICAgICAgICB0b3A6IDAuMCU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCiAgICAKICAgICAgICAgICAgICAgIDxzdHlsZT4KICAgICAgICAgICAgICAgICAgICAubGVhZmxldC1pbWFnZS1sYXllciB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIG9sZCBhbmRyb2lkL3NhZmFyaSovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogLXdlYmtpdC1vcHRpbWl6ZS1jb250cmFzdDsKICAgICAgICAgICAgICAgICAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBjcmlzcC1lZGdlczsgLyogc2FmYXJpICovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogcGl4ZWxhdGVkOyAvKiBjaHJvbWUgKi8KICAgICAgICAgICAgICAgICAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiAtbW96LWNyaXNwLWVkZ2VzOyAvKiBmaXJlZm94ICovCiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlLXJlbmRlcmluZzogLW8tY3Jpc3AtZWRnZXM7IC8qIG9wZXJhICovCiAgICAgICAgICAgICAgICAgICAgICAgIC1tcy1pbnRlcnBvbGF0aW9uLW1vZGU6IG5lYXJlc3QtbmVpZ2hib3I7IC8qIGllICovCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgPC9zdHlsZT4KICAgICAgICAgICAgCjwvaGVhZD4KPGJvZHk+ICAgIAogICAgCiAgICAgICAgICAgIDxkaXYgY2xhc3M9ImZvbGl1bS1tYXAiIGlkPSJtYXBfYjlmNDliYzFiNzAzNDM1MDg2MGJjZjUwZjYyMDg1MDAiID48L2Rpdj4KICAgICAgICAKPC9ib2R5Pgo8c2NyaXB0PiAgICAKICAgIAogICAgICAgICAgICB2YXIgbWFwX2I5ZjQ5YmMxYjcwMzQzNTA4NjBiY2Y1MGY2MjA4NTAwID0gTC5tYXAoCiAgICAgICAgICAgICAgICAibWFwX2I5ZjQ5YmMxYjcwMzQzNTA4NjBiY2Y1MGY2MjA4NTAwIiwKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBjZW50ZXI6IFswLjAsIC04LjU5MjI5NzYwNzY4MDAwMmUtMTddLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogMSwKICAgICAgICAgICAgICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICAgICAgICAgICAgICBwcmVmZXJDYW52YXM6IGZhbHNlLAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApOwoKICAgICAgICAgICAgCgogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyXzdiYzNiOWFmZjA1MjRmNDdhZmI1NmVjODE2MGYyODdiID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAiaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmciLAogICAgICAgICAgICAgICAgeyJhdHRyaWJ1dGlvbiI6ICJEYXRhIGJ5IFx1MDAyNmNvcHk7IFx1MDAzY2EgaHJlZj1cImh0dHA6Ly9vcGVuc3RyZWV0bWFwLm9yZ1wiXHUwMDNlT3BlblN0cmVldE1hcFx1MDAzYy9hXHUwMDNlLCB1bmRlciBcdTAwM2NhIGhyZWY9XCJodHRwOi8vd3d3Lm9wZW5zdHJlZXRtYXAub3JnL2NvcHlyaWdodFwiXHUwMDNlT0RiTFx1MDAzYy9hXHUwMDNlLiIsICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwgIm1heE5hdGl2ZVpvb20iOiAxOCwgIm1heFpvb20iOiAxOCwgIm1pblpvb20iOiAwLCAibm9XcmFwIjogZmFsc2UsICJvcGFjaXR5IjogMSwgInN1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SDIyVExhZXNuK2M0ZGRTemp2VXUreGdrUnZlazRibk14UFhGeVo1ZWZOZmRoMk8vL3gzc004OXg2cWp2bmpSeTJjZExqUXphbEFySWR3MzFtK2duLzhURkFsSU5nbjNtT1U1ZFFKcjFMdnZZSlFEUDRJeXJqUm5kV1JIa3NnMkNXcGQ5dktHeFlUQUd4NjVNQlFleUl4Qm5SN1krOEhEVnh4c2RId05qZUh6a21pUHdjTlhIRy85ekhJcnB3NE5lTTc0RVNaQUVTWkFFU1pBRVNaRDArZzlJdXFJT2NjV3R6MjRoUHJ2cExrQ0l1d0M2bnhUaWZwTHVUSWE0TTZsNzNDSHVjZXZia2hEZmx1aDdOMzA1R1Ewa3JRVUlzUlpBcTBwQ3JDclIrcVFRNjVPMDBpM0VTamV0bWRUQzBtZ2dhUjEzaUhYY2VpSkFqMDFFQTBsUEtZVjRTa25QdSttaHdHZ2c2Um5jRU0vZzZtbHVQZkllRFNUdE1LRnRPS0tCcEYxdnREVlFOSkMwRTVlMkt4T2tPWU9rZlNhMUdXYzBrTFQzclRZSUZxUTVnNlNkM2JYOXZTRE5HU1Q5Ym9sKzNFV1FCT2w2Z3FUZmI5T1A0QW1TSUYxUGtQUTd0L3F4WUVFU0pFRVNKRUVTSklVZ0NaSWdDWklnQ1pJZ0tRUkprQVJKa0FSSmtOeU52d0NTSTFTb0JBb2h6QUFBQUFCSlJVNUVya0pnZ2c9PSIsCiAgICAgICAgICAgICAgICBbWy05MC4wLCAtMTgwLjBdLCBbOTAuMCwgMTgwLjBdXSwKICAgICAgICAgICAgICAgIHsib3BhY2l0eSI6IDAuMjV9CiAgICAgICAgICAgICkuYWRkVG8obWFwX2I5ZjQ5YmMxYjcwMzQzNTA4NjBiY2Y1MGY2MjA4NTAwKTsKICAgICAgICAKPC9zY3JpcHQ+ onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x217e6395ac8>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cartopy.crs as ccrs\n",
    "from cartopy.img_transform import warp_array\n",
    "\n",
    "source_extent = [lon.min(), lon.max(), lat.min(), lat.max()]\n",
    "\n",
    "new_data = warp_array(colored_data,\n",
    "                      target_proj=ccrs.GOOGLE_MERCATOR,\n",
    "                      source_proj=ccrs.PlateCarree(),\n",
    "                      target_res=data.shape,\n",
    "                      source_extent=source_extent,\n",
    "                      target_extent=None,\n",
    "                      mask_extrapolated=False)\n",
    "\n",
    "\n",
    "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
    "\n",
    "folium.raster_layers.ImageOverlay(\n",
    "    image=new_data[0],\n",
    "    bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
    "    opacity=0.25\n",
    ").add_to(m)\n",
    "\n",
    "m.save(os.path.join('results', 'GeodedeticImageOverlay_2.html'))\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "TODO: Try [rasterio](https://github.com/mapbox/rasterio/blob/ca75cf0a842943c1b3da4522e6ea3500215130fd/docs/reproject.rst).  Rasterio can warp images and arrays."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Compare to original"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From https://scitools.org.uk/cartopy/docs/latest/gallery/waves.html\n",
    "\n",
    "![](https://scitools.org.uk/cartopy/docs/latest/_images/sphx_glr_waves_001.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
